﻿using DevelopTool.Common;
using DevelopTool.Model.CommonModels;
using DevelopTool.Model.Enums;
using System;

namespace DevelopTool.Bll.WiFiFixatorBlls
{
    public class WiFiFixatorBll
    {
        /// <summary>
        /// 启动设定的监控WiFi
        /// </summary>
        public void StartJob()
        {
            if (!Setting.WiFiFixator.AutoStartFixator) return;

            //从配置文件中读取监控的WiFi ssid
            string wifiSSID = Setting.WiFiFixator.FixatorSSID;
            if (string.IsNullOrEmpty(wifiSSID)) return;

            QuartzHelper.DeleteJob(wifiSSID, "WiFiFixator");

            //新增Quartz任务
            if (!QuartzHelper.AddSimpleTriggerJob(typeof(WiFiFixatorJob), wifiSSID, "WiFiFixator", -1,
                Setting.WiFiFixator.FixatorIntervalTime, DateTime.Now, DateTime.Now.AddYears(100)))
            {
                WiFiFixatorLogBll.AddLog(new LogModel(LogType.Warning, $"【{wifiSSID}】开启WiFi监控失败"));
            }
        }
    }
}
